import { injectReducer } from '../../store/reducers'
import RoomManager from './components/RoomManager'
import WilddogHome from './components/WilddogHome'
/*  Note: Instead of using JSX, we recommend using react-router
    PlainRoute objects to build route definitions.   */
function requireAuth (nextState, replace) {
  const token = localStorage.getItem('@USER')
  if (!token) replace({
      pathname: '/',
      state: { nextPathname: nextState.location.pathname }
    })
}
export default (store) => ({
  path: 'wilddog',
  indexRoute: {
    component: WilddogHome
  },
  childRoutes: [{
    path: 'room/:roomId',
    component: RoomManager
  }],
  /*  Async getComponent is only invoked when route matches   */
  getComponent(nextState, cb) {
    /*  Webpack - use 'require.ensure' to create a split point
        and embed an async module loader (jsonp) when bundling   */
    require.ensure([], (require) => {
      /*  Webpack - use require callback to define
          dependencies for bundling   */
      const Wilddog = require('./containers/WilddogContainer').default
      const reducer = require('./modules/wilddog').default

      /*  Add the reducer to the store on key 'counter'  */
      injectReducer(store, { key: 'wilddog', reducer })

      /*  Return getComponent   */
      cb(null, Wilddog)

      /* Webpack named bundle   */
    }, 'wilddog')
  }
})
